package top.hidoctor.auscultation.feature.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;

import java.util.Arrays;
import java.util.List;

import top.hidoctor.auscultation.R;
import top.hidoctor.auscultation.adapter.GongzuotaiBzAdapter;
import top.hidoctor.auscultation.adapter.GongzuotaiShAdapter;
import top.hidoctor.auscultation.base.BaseActivity;
import top.hidoctor.auscultation.bean.AuditBean;
import top.hidoctor.auscultation.bean.AuditListBean;
import top.hidoctor.auscultation.net.c.AuditDetailContract;
import top.hidoctor.auscultation.net.p.AuditDetailPresenter;

public class WorkCenterShActivity extends BaseActivity implements AuditDetailContract.View {

    private RecyclerView recycler;
    private GongzuotaiShAdapter adapter;
    private Button btnFinish;
    private String type;
    private AuditListBean.ResultBean info;
    private AuditDetailPresenter presenter;
    private TextView tvTitle;
    private AuditBean auditBean;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.act_center);
        presenter = new AuditDetailPresenter(this, this);
        initView();
        inEvent();
    }

    private void inEvent() {
        info = (AuditListBean.ResultBean) getIntent().getSerializableExtra("info");
        tvTitle.setText(info.getName());
        presenter.getDetail(info.getId());
    }

    private void initView() {

        Toolbar toolbar = findViewById(R.id.toolbar);
        tvTitle = findViewById(R.id.tv_title);
        toolbar.setNavigationIcon(R.mipmap.ic_back_left);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });

        btnFinish = findViewById(R.id.btn_finish);
        recycler = findViewById(R.id.recycler);
        recycler.setLayoutManager(new LinearLayoutManager(this));
        recycler.setAdapter(adapter = new GongzuotaiShAdapter(R.layout.item_shenhe_center, null));
        recycler.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
        adapter.setOnRecyclerViewItemChildClickListener(new BaseQuickAdapter.OnRecyclerViewItemChildClickListener() {
            @Override
            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                AuditBean.SampleBean bean = (AuditBean.SampleBean) adapter.getData().get(position);
                switch (view.getId()) {
                    case R.id.btn_shenhe:
                        Intent intent = new Intent(WorkCenterShActivity.this, ShLabelDetailActivity.class);
                        intent.putExtra("type", 1);
                        intent.putExtra("id", bean.getAuditId());
                        intent.putExtra("labelId", bean.getLabelId());
                        intent.putExtra("sampleId", bean.getId());
                        intent.putExtra("info", bean.getSampleDetail());
                        intent.putExtra("status", bean.getAuditStatus());
                        startActivity(intent);
                        break;
                }
            }
        });
        btnFinish.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                showToast("您还有为审核完成的标注");
            }
        });
    }

    @Override
    public void getDetailSuc(AuditBean bean) {
        this.auditBean = bean;
        List<AuditBean.SampleBean> sample = bean.getSample();
        adapter.setNewData(sample);
    }
}
